package com.cskaoyan.service.impl;

import com.cskaoyan.mapper.OrderGoodsMapper;
import com.cskaoyan.mapper.OrderMapper;
import com.cskaoyan.mapper.UserMapper;
import com.cskaoyan.model.vo.ChartVO;
import com.cskaoyan.model.vo.GoodsChartVO;
import com.cskaoyan.model.vo.GrowingUserVO;
import com.cskaoyan.model.vo.OrderChartVO;
import com.cskaoyan.service.StatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: mall38
 * @description: 统计报表
 * @author: Lexis
 * @create: 2022-05-06 19:02
 **/
@Service
public class StatServiceImpl implements StatService {
    @Autowired
    UserMapper userMapper;
    @Autowired
    OrderGoodsMapper orderGoodsMapper;
    @Autowired
    OrderMapper orderMapper;


    @Override
    /**
     * @author: lixiaosheng
     * @description: 根据日期查询用户日增长量
     * @date: 2022/5/6 19:26
     */
    public ChartVO<GrowingUserVO> getGrowingUsers() {
        ChartVO<GrowingUserVO> chartVO = new ChartVO<>();
        chartVO.setColumns(new String[]{"day", "users"});
        List<GrowingUserVO> rows = userMapper.selectUsersGroupByDay();
        chartVO.setRows(rows);
        return chartVO;
    }

    @Override
    /**
     * @author: lixiaosheng
     * @description: 根据日期查询商品报表数据
     * @date: 2022/5/6 19:47
     */
    public ChartVO<GoodsChartVO> getOrderGoods() {
        ChartVO<GoodsChartVO> chartVO = new ChartVO<>();
        chartVO.setColumns(new String[]{"day", "orders", "products", "amount"});
        List<GoodsChartVO> rows = orderGoodsMapper.selectOrderGoodsDataGroupByDay();
        chartVO.setRows(rows);
        return chartVO;
    }

    @Override
    /**
     * @author: lixiaosheng
     * @description: 根据日期查询订单报表数据
     * @date: 2022/5/6 20:45
     */
    public ChartVO<OrderChartVO> getOrder() {
        ChartVO<OrderChartVO> chartVO = new ChartVO<>();
        chartVO.setColumns(new String[]{"day", "orders", "customers", "amount", "pcr"});
        List<OrderChartVO> rows = orderMapper.selectOrderDataGroupByDay();
        chartVO.setRows(rows);
        return chartVO;
    }
}
